package com.example.provider_rocketmq.controller;


import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
public class Provider {
    @Resource
    private RocketMQTemplate rocketMQTemplate;
    @GetMapping("sendMsg")
    public String sendMessage() throws Exception {

        rocketMQTemplate.convertAndSend("mytopic","Hello RocketMQ");
//        DefaultMQProducer producer = new DefaultMQProducer("my-group1");
//        producer.setNamesrvAddr("192.168.56.10:9876");
//        producer.setSendMsgTimeout(15000);
//        producer.start();
//
//        Message message = new Message("myTopic", "TagA", "key1", ("Hello RocketMq").getBytes(RemotingHelper.DEFAULT_CHARSET));
//
//        SendResult send = producer.send(message);
//        System.out.println(send);
        return "生产success";
    }
    @RequestMapping("/send2RedisMsg")
    public String sendRedis(){
        final String value="value1*";
        rocketMQTemplate.convertAndSend("redisTopic",value);
        return "生产redis";
    }
}
